package com.lanqiao.controller;

import cn.hutool.json.JSONUtil;
import com.lanqiao.entity.OrderInfo;
import com.lanqiao.service.OrderService;
import com.lanqiao.service.ShufflingService;
import com.lanqiao.service.impl.OrderSerImpl;
import com.lanqiao.service.impl.ShufflingSerImpl;
import org.lanqiao.mvc.entity.ModelAndView;
import org.lanqiao.mvc.entity.YockMvcAnnotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@YockMvcAnnotation.Controller("/order")
public class OrderController {

    private OrderService order = new OrderSerImpl();

    //订单列表
    private ShufflingService shuffling = new ShufflingSerImpl();

    @YockMvcAnnotation.RequestMapping("/selectorder.do")
    @YockMvcAnnotation.ResponseDispatch("/WEB-INF/view/order/ordermanager.jsp")
    public ModelAndView selectorder(
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception{
        ModelAndView model = new ModelAndView();

        return model;
    }


    /**
     * 查询订单数据
     * @param request
     * @param response
     * @return
     */
    @YockMvcAnnotation.RequestMapping("/selectinfo.do")
    @YockMvcAnnotation.ResponseBody
    public String selectinfo(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        //告诉前端返回来的是一个json数据
        response.setContentType("application/json;charset=utf-8");
        // 保存图片名称的集合
        Map<String, Object> map = new HashMap<>();

        List<OrderInfo> orderInfos = order.selectOrder();


        map.put("code",200);
        map.put("data",orderInfos);

        String jsonStr = JSONUtil.toJsonStr(map);


        return jsonStr;
    }







}
